<!--  -->
<template>
  <div class="box">
    <!-- 选择时间 -->
    <div class="edit_list">
      <div class="edit_participate">
        <div class="l_circular">
          <svg-icon iconClass="chen-chuanjian" class="zhuo_back"></svg-icon>
        </div>
        <div class="l_title">
          <p>6</p>
          <p class="p_number">参与人数（人）</p>
        </div>
      </div>
      <div class="edit_member">
        <div class="r_circular">
          <svg-icon iconClass="chen-chuanjian" class="zhuo_back"></svg-icon>
        </div>
        <div class="r_title">
          <p>1</p>
          <p class="p_number">成员数量（个）</p>
        </div>
      </div>
    </div>
    <div class="time_select">
      <h1>时间选择：</h1>
      <ul>
        <li
          v-for="(item, index) in timeSelectList"
          :key="index"
          :class="carIndex === index ? 'active' : ''"
          @click="changeTab(index)"
        >
          {{ item.name }}
        </li>
      </ul>
      <div class="time_select_block">
        <el-date-picker v-model="value1" type="date"></el-date-picker>
      </div>
    </div>
    <!-- 砍价状态 -->
    <div class="say_state">
      <h1>砍价状态</h1>
      <el-select
        v-model="commodityState"
        @change="changeDate(pageIndex, pageSize)"
        clearable
        placeholder="请选择"
      >
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100% text-align:center"
      max-height="400"
    >
      <el-table-column prop="id" label="ID" align="center"> </el-table-column>
      <el-table-column prop="url" label="砍价图片" align="center">
        <template slot-scope="scope">
          <img :src="scope.row.url" />
        </template>
      </el-table-column>
      <el-table-column prop="name" label="砍价商品名称" align="center">
      </el-table-column>
      <el-table-column prop="recommend" label="商品介绍" align="center">
      </el-table-column>
      <el-table-column prop="price" label="砍价价格" align="center">
      </el-table-column>
      <el-table-column prop="introduce" label="总共砍次数" align="center">
      </el-table-column>
      <el-table-column prop="residue" label="剩余砍价次数" align="center">
      </el-table-column>
      <el-table-column prop="begin" label="开始时间" align="center">
      </el-table-column>
      <el-table-column prop="finish" label="结束时间" align="center">
      </el-table-column>
      <el-table-column prop="state" label="砍价状态" align="center">
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="compile(scope.row)"
            >查看详情</el-button
          >
          <tk
            v-if="showPile"
            :newList="newList"
            :name="'砍价'"
            @isShow="isShow"
          ></tk>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <footer>
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="1000"
      />
    </footer>
  </div>
</template>

<script>
import { fetchList } from "../../../../api/productData";
import tk from "../components/tk";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: { tk },
  data() {
    //这里存放数据
    return {
      timeSelectList: [
        {
          name: "全部",
        },
        {
          name: "今天",
        },
        {
          name: "昨天",
        },
        {
          name: "最近7天",
        },
        {
          name: "最近30天",
        },
        {
          name: "本月",
        },
        {
          name: "本年",
        },
      ],
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "进行中",
          label: "进行中",
        },
        {
          value: "已结束",
          label: "已结束",
        },
        {
          value: "准备中",
          label: "准备中",
        },
      ],
      showPile: false,
      commodityState: null,
      currentPage4: 1,
      tableData: [],
      value1: "",
      carIndex: 0,
      pageIndex: 1,
      pageSize: 5,
      total: 0,
      scops: {},
      value: "",
      flag: false,
      newList: [],
      listQuery: {
        page: 1,
        limit: 4,
        sort: "+id",
        total: 0,
      },
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getList() {
      fetchList(this.listQuery).then((res) => {
        this.tableData = res.data.items;
        this.newList = res.data.items;
      });
    },
    //分页
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    //模糊搜索
    changeDate() {
      const data = this.newList.filter(
        (item) => item.state === this.commodityState
      );
      this.tableData = data;
    },
    //点击查看详情
    compile(row) {
      this.showPile = !this.showPile;
      this.newList = row;
    },
    isShow(e) {
      this.showPile = e;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getList();
  },
};
</script>
<style lang="scss" scoped>
* {
  list-style: none;
  box-sizing: border-box;
}
.box {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 20px 20px 10px 20px;
  display: flex;
  flex-direction: column;
  .edit_list {
    width: 100%;
    height: 90px;
    display: flex;
    justify-content: left;
    // 左边
    .edit_participate,
    // 右边
    .edit_member {
      width: 20%;
      height: 90%;
      min-width: 180px;
      background: #f5f7f9;
      margin-right: 10px;
      border-radius: 10px;
      display: flex;
      align-items: center;

      .l_circular {
        height: 40px;
        width: 40px;
        margin: 0 15px;
        text-align: center;
        line-height: 40px;
        background: #4d7cfe;
        border-radius: 50%;
        .zhuo_back {
          color: #ffff;
          font-size: 18px;
        }
      }
      .l_title {
        .p_number {
          font-size: 12px;
          color: #aab8c8;
        }
      }
    }
    // 右边
    .edit_member {
      // width: 20%;
      // height: 90%;
      // min-width: 180px;
      // border-radius: 10px;
      // background: #f5f7f9;
      // display: flex;
      // justify-content: center;
      // align-items: center;
      .r_circular {
        height: 40px;
        width: 40px;
        margin: 0 15px;
        text-align: center;
        line-height: 40px;
        background: #ffab2b;
        border-radius: 50%;
        .zhuo_back {
          color: #ffff;
          font-size: 18px;
        }
      }
      .r_title {
        .p_number {
          font-size: 12px;
          color: #aab8c8;
        }
      }
    }
  }
  .active {
    color: #eff5ff !important;
    background: #1890ff;
  }
  .time_select {
    width: 100%;
    height: 65px;
    display: flex;
    align-items: center;

    h1 {
      font-size: 16px;
      font-weight: bolder;
      color: #626168;
    }
    ul {
      margin-left: 15px;
      display: flex;
      height: 39px;
      width: 50%;

      li {
        flex: 1;
        height: 38px;
        text-align: center;
        // width: auto;
        // min-width: 75px;
        line-height: 38px;
        padding: 0 10px;
        border: 1px solid #ebecf0;
        color: #676669;
      }
    }
  }
  .time_select_block {
    margin-left: 15px;
    // width: 10%;
  }
  .say_state {
    width: 100%;
    height: 60px;
    display: flex;
    margin-left: 1150px;
    align-items: center;

    h1 {
      display: flex;
      font-size: 16px;
      font-weight: bolder;
      color: #626168;
      margin-right: 10px;
    }
    .el-select {
      height: 40px;
    }
    .search_h1 {
      margin-left: 30px;
    }
  }
  footer {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
  }
}
</style>
